<?php

/**
 * Subclass for representing a row from the 'ringtone_category' table.
 *
 * 
 *
 * @package lib.model
 */ 
class RingtoneCategory extends BaseRingtoneCategory
{
    public function  __toString() {
        return $this->getName();
    }

    public function getRingtoneCount() {
        return RingtoneCategoryPeer::getRingtoneCount($this->getId());
    }

    public function getChildrenCount() {
        return RingtoneCategoryPeer::getChildrenCount($this->getId());
    }

    public function isParent() {
        return ($this->getId() == $this->getParentId());
    }

    public function isEmpty() {
        if($this->isParent()) {
            return !$this->getChildrenCount();
        } else {
            return !$this->getRingtoneCount();
        }
    }

    public function getListChildren() {
        return RingtoneCategoryPeer::getListChildren($this->getId());
    }
	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}
		
		if (!$this->isEmpty())
		{
			throw new Exception('catecon', 1);
		}
		
		if ($con === null) {
			$con = Propel::getConnection(RingtoneCategoryPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			RingtoneCategoryPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}
	
	public function getListParents()
	{
		$c = new Criteria();
		$c->add(RingtoneCategoryPeer::ENABLED, 1);
		$c->addJoin(RingtoneCategoryPeer::ID, RingtoneCategoryPeer::PARENT_ID);
		return RingtoneCategoryPeer::doSelect($c);
	}

	
}
